<?php

if(isset($_REQUEST['frm_aksi'])){
	require_once('../class/class.libur.php');
	if($_REQUEST['frm_aksi']=="save"){
		$tgl_libur=date('Y-m-d', strtotime($_POST['tgl_libur']));
		$uraian=$_POST['uraian'];
		$idHari=$_POST['idHari'];

		$year=explode("-", $tgl_libur);
		$tahun=$year[0];
		$libur=new Libur();
		$msg=false;
		$sukses="Berhasil Rekam Hari Libur";
		$error="Gagal Rekam Hari Libur";

		$libur->tgl_libur=$tgl_libur;
		$libur->uraian=$uraian;
		$libur->tahun=$tahun;
		$libur->idHari=$idHari;

		$liburDao=new LiburDao();
		if($liburDao->cekLibur($tgl_libur)){
			$error="Tanggal Sudah Direkam";
		}else{
			$create=$liburDao->createLibur($libur);
			if($create){
				$msg=true;
			}
		}

		$data=array(
			'msg' => $msg,
			'eror' => $error,
			'sukses' => $sukses,
			);

		echo json_encode($data);

	}
	if($_REQUEST['frm_aksi']=="edit"){
		
		$liburDao=new LiburDao();
		$id=$_POST['id_aksi'];
		$msg=true;
		$error='';
		$libur=$liburDao->getLibur($id);
		if($libur==false){
			$error="Data Hari Libur Tidak Ada";
			$msg=false;
		}

		$data=array(
			'edit' => true,
			'msg' => $msg,
			'eror' => $error,
			'libur' => $libur,
			);

		echo json_encode($data);

	}
	if($_REQUEST['frm_aksi']=="simpan_edit"){
		$tgl_libur=date('Y-m-d', strtotime($_POST['tgl_libur']));
		$uraian=$_POST['uraian'];
		$id=$_POST['id_aksi'];
		$idHari=$_POST['idHari'];
		$year=explode("-", $tgl_libur);
		$tahun=$year[0];
		$libur=new Libur();
		$msg=false;
		$sukses="Berhasil Simpan Hari Libur";
		$error="Gagal Ubah Hari Libur";
		$libur->id=$id;
		$libur->tgl_libur=$tgl_libur;
		$libur->uraian=$uraian;
		$libur->tahun=$tahun;
		$libur->idHari=$idHari;

		$liburDao=new LiburDao();
		
		$edit=$liburDao->updateLibur($libur);
		if($edit){
			$msg=true;
		}

		$data=array(
			'msg' => $msg,
			'eror' => $error,
			'sukses' => $sukses,
			);

		echo json_encode($data);

	}
	if($_REQUEST['frm_aksi']=="hapus"){
		
		$id=$_POST['id_aksi'];

		$msg=false;
		$sukses="Berhasil Hapus Hari Libur";
		$error="Gagal Hapus Hari Libur";
		
		$liburDao=new LiburDao();
		
		$hapus=$liburDao->deleteLibur($id);
		if($hapus){
			$msg=true;
		}

		$data=array(
			'msg' => $msg,
			'eror' => $error,
			'sukses' => $sukses,
			);

		echo json_encode($data);

	}
}

if(isset($_REQUEST['aksi_get_libur'])){
	require_once('../class/class.libur.php');

	$liburDao=new LiburDao();

	$tahun=$_REQUEST['tahun'];

	$liburs=$liburDao->getAllByTahun($tahun);
	$msg=false;
	if($liburs!=false){
		$msg=true;
	}

	$data=array(
		'msg'=>$msg,
		'libur' => $liburs,
		);

	echo json_encode($data);
}

?>